//
//  YYTCmtBannerCell.swift
//  Yuyuto
//
//  Created by Arthur on 2017/6/21.
//  Copyright © 2017年 yuyuto. All rights reserved.
//

import UIKit

let  DFBannerHeaderViewHeight = normalize(value: 175)

@objc protocol DFBannerCellDelegate {
    //头部点击
    func bannerDidClick(cell:DFBannerCell, currentIndex:Int)
}

class DFBannerCell: UICollectionViewCell, DFBannerViewDelegate {
    
    var imagesUrlStringArray:Array<String> = []
    weak var delegate:DFBannerCellDelegate?
    lazy var bannerView:DFBannerView = {
        [unowned self] in
        let temp = DFBannerView(frame: self.bounds)
        temp.delegate = self
        return temp
    }()
    
    override init(frame: CGRect) {
        super.init(frame: frame)
        self.addSubview(self.bannerView)
    }
    
    required init?(coder aDecoder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }
    
    //MARK:- 刷新banner
    func update(viewModel: DFHomeVM) -> Void {
        let bannerItems = viewModel.bannerArray
        if bannerItems.count != 0 {
            imagesUrlStringArray = []
            for item in bannerItems {
                imagesUrlStringArray.append(item.path)
            }
            self.bannerView.update(imageURLStringGroup: imagesUrlStringArray)
        }
    }
    
    func dfBannerView(_ bannerView: DFBannerView, didSelectItemAt index: Int) {
        self.delegate?.bannerDidClick(cell: self, currentIndex: index)
    }
    
    func dfBannerView(_ bannerView: DFBannerView, didScrollTo index: Int) {
//        let topVC = YYTUIManager.sharedInstance.tabBarController.topViewController()
//        if topVC is YYTCmtMainVC {
//            let offset: CGPoint = (topVC as! YYTCmtMainVC).collectionView.contentOffset
//            if offset.y <= CmtBannerCellHeight {
////                MobClick.event(YYTLogEventBannerShow, attributes: ["url": imagesUrlStringArray[index]])
//                YYTAnalytics.event(YYTLogEventBannerShow, attributes: ["url": imagesUrlStringArray[index]])
//            }
//        }
    }
}
